//
//  AppDelegate.m
//  HappinessTrip
//
//  Created by dllo on 15/9/30.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"
#import "PlayViewController.h"
#import "DestinationViewController.h"
#import "UserViewController.h"


#import "WelcomeViewController.h"//欢迎页

#import "UMSocial.h"

@interface AppDelegate ()

@end

@implementation AppDelegate
-(void)dealloc
{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    _window.backgroundColor = [UIColor whiteColor];
    [_window makeKeyAndVisible];
    [_window release];
    
    //分享注册账号
    [UMSocialData setAppKey:@"507fcab25270157b37000010"];
    
    ViewController *vc = [[ViewController alloc]init];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
    nav.navigationBar.translucent = NO;
    vc.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"心推荐" image:[UIImage imageNamed:@"1"]tag:1000];
    PlayViewController *pvc = [[PlayViewController alloc]init];
    UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:pvc];
    nav1.navigationBar.translucent = NO;
    pvc.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"舒心玩" image:[UIImage imageNamed:@"2"] tag:1001];
    DestinationViewController *dvc = [[DestinationViewController alloc]init];
    UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:dvc];
    nav2.navigationBar.translucent = NO;
    dvc.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"开心地" image:[UIImage imageNamed:@"3"] tag:1003];
    UserViewController *uvc = [[UserViewController alloc]init];
    UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:uvc];
    nav3.navigationBar.translucent = NO;
    uvc.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我的心" image:[UIImage imageNamed:@"4"] tag:1004];
    UITabBarController *tabBarController = [[UITabBarController alloc]init];
    tabBarController.viewControllers = @[nav, nav1, nav2, nav3];
    
    //设置tabBar不透明
    tabBarController.tabBar.translucent = NO;
    tabBarController.tabBar.tintColor = [UIColor colorWithRed:0.56 green:0.53 blue:0.93 alpha:1];
    
    //修改上下颜色
    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:1 green:0.95 blue:0.85 alpha:1]];
    tabBarController.tabBar.barTintColor = [UIColor colorWithRed:1 green:0.95 blue:0.85 alpha:1];
    [vc release];
    [pvc release];
    [dvc release];
    [uvc release];
    [nav release];
    [nav1 release];
    [nav2 release];
    [nav3 release];
    
    
    //检查APP是否首次运行(欢迎页)
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"00001"]) {
        WelcomeViewController *wc = [[WelcomeViewController alloc]init];
        wc.tabBarController = tabBarController;
        [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"00001"];
        _window.rootViewController = wc;
        [wc release];
    }
    else {
        _window.rootViewController = tabBarController;
    }
    
    sleep(1);
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
